<?
 include("../header.php");
 include("../lib/config.php");
 $show 	= $HTTP_GET_VARS['show'];
 $nik	= $HTTP_GET_VARS['nik'];
 $nama	= $HTTP_GET_VARS['nama'];
 $no	= $HTTP_GET_VARS['no'];
 $op	= $HTTP_GET_VARS['op'];
 
?>
<script type="text/javascript">
	function LoadFocus(){
		document.forms[0].elements[0].focus();
	}
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function show_popup(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
	
	function ValidateF(){
		var F = document.forms['plafon_awal'];
		
		if(F.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			F.nik.focus();
			return false;
		}
		
		if(F.periode.value == "")
		{
			alert("Field : Periode tidak boleh kosong ...");
			F.periode.focus();
			return false;
		}
		
		if(F.date_setup.value == "")
		{
			alert("Field : Tanggal Setting tidak boleh kosong ...");
			F.date_setup.focus();
			return false;
		}

		if(F.plafon_rawat_jalan.value == "")
		{
			alert("Field : Rawat Jalan tidak boleh kosong ...");
			F.plafon_rawat_jalan.focus();
			return false;
		}


		if(F.plafon_kaca_mata.value == "")
		{
			alert("Field : Kaca Mata tidak boleh kosong ...");
			F.plafon_kaca_mata.focus();
			return false;
		}

		F.submit();
	}
	
	function ValidateR(){
		var F = document.forms['rekening'];
		
		if(F.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			F.nik.focus();
			return false;
		}
		
		if(F.no_rek.value == "")
		{
			alert("Field : Nomor Rekening tidak boleh kosong ...");
			F.no_rek.focus();
			return false;
		}
		
		if(F.nama_rek.value == "")
		{
			alert("Field : Nama Rekening tidak boleh kosong ...");
			F.nama_rek.focus();
			return false;
		}
		
		if(F.nama_bank.value == "")
		{
			alert("Field : Nama Bank harus dipilih ...");
			F.nama_bank.focus();
			return false;
		}
		
		F.submit();
	}

</script>
<script language="javascript" src="../js/calendar.js"></script>
<?
if($show == "plafon_awal"){
	if($op == "edit"){
		$Faction = "../lib/update.php";
		$Vbutton = "Update";
		$sql = mssql_query("WITH Q AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, CONVERT(CHAR(12), DateSetup, 103) Tanggal,* FROM VMedicalSetup WHERE NIK='$nik') SELECT * FROM Q WHERE No='$no' ",$conn);
		$row = mssql_fetch_array($sql);
	}
	else{
		$Faction = "../lib/save.php";
		$Vbutton = "Simpan";
		$row[NIK] 	= $nik;
		$row[Nama] 	= $nama;
	}
	
?>
<table>
 <tr>
  <td>
	<form name="plafon_awal" action="<?=$Faction?>" method="post">
  <table>
   <tr> 
    <td width="100">NIK</td>
	<td><input type="text" name="nik" value="<?=$row[NIK]?>" readonly="" />
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
	</td>
   </tr>
   <tr> 
    <td width="100">Nama</td>
	<td><input type="text" value="<?=$row[Nama]?>" name="nama" size="50" readonly="" /></td>
   </tr>   
  </table>
  </td>
 </tr>
 <tr>
  <td><hr noshade="noshade" size="-1" color="#EFEFEF" /></td>
 </tr>
 <tr>
  <td>
   <table width="100%" border="0">
    <tr>
	 <td width="50%">Periode:</td>
	 <td>
		<select name="periode">
         <?
         	for($i=1990;$i<=(date("Y")+100);$i++){
				echo"
				<option value='$i' ";
				if($op == "edit"){
					if($row[Periode] == $i){
						echo" selected";
					}
				}
				else{
					if(date("Y") == $i){
						echo" selected";
					}
				}
				echo">$i</option>
				";
			}
		 ?>
        </select>
     </td>
	</tr>
	<tr>
	 <td>Tanggal Setting:</td>
	 <td><input type="text" name="date_setup" value="<?
	 if(empty($row[Tanggal])){
	 	echo date("d/m/Y");
	 }
	 else{
	 	echo $row[Tanggal];
	 }
	 ?>" maxlength="10" size="11" /> <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a></td>
	</tr>
<?
	 if($op == "edit"){
	 	$PRJ = $row[PlafonRawatJalan];
		$PRI = $row[PlafonRawatInap];
		$PKC = $row[PlafonKacaMata];
	 }
	 else{
	 	$qplaf = mssql_query("SELECT * FROM VMedicalSetup WHERE NIK='$nik' ORDER BY Periode DESC",$conn);
		if(mssql_num_rows($qplaf) > 0){
			$rplaf = mssql_fetch_array($qplaf);
			$PRJ = $rplaf[PlafonRawatJalan];
			$PRI = $rplaf[PlafonRawatInap];
			$PKC = $rplaf[PlafonKacaMata];
		}
		else{
			$PRJ = 0;
			$PRI = 0;
			$PKC = 0;
		}
	 }
?>	
	<tr>
	 <td>Plafon Pengobatan/Rawat Jalan: <!--Rawat Jalan--></td>
	 <td><input type="text" value="<?=$PRJ?>" name="plafon_rawat_jalan"/></td>
	</tr>
	<tr>
	 <td>Plafon Rawat Inap: <!--Rawat Jalan--></td>
	 <td><input type="text" value="<?=$PRI?>" name="plafon_rawat_inap"/></td>
	</tr>
	<tr>
	 <td>Plafon Kaca Mata:</td>
	 <td><input type="text" value="<?=$PKC?>" name="plafon_kaca_mata" /></td>
	</tr>
	<tr>
	 <td colspan="2"><hr noshade="noshade" size="-2" color="#EFEFEF" /></td>
	</tr>
	<tr>
	 <td colspan="2" align="right">
	  <input type="hidden" name="cat" value="plafon_awal" />
	  <input type="hidden" name="no" value="<?=$row[No]?>" />
	  <input type="button" value="Batal" onclick="Javascript:history.back();" class="button" />
	  <input type="button" value="<?=$Vbutton?>" onclick="Javascript:ValidateF()" class="button" />
	  </td>
	</tr>
   </table>
   </form>
  </td>
 </tr>
</table>
<script type="text/javascript">
var g = document.forms['plafon_awal'];
MaskInput(g.periode,"9999");
MaskInput(g.plafon_kaca_mata,"9999999999999");
MaskInput(g.plafon_rawat_jalan,"9999999999999");
MaskInput(g.plafon_rawat_inap,"9999999999999");
//]]>
</script>
<?
	}
	elseif($show == "rekening"){
	// cek nomor rekening di database
	
	$srek	= mssql_query("SELECT * FROM MedicalNoRekening WHERE NIK='$nik' ",$conn);
	$crek	= mssql_num_rows($srek); // count of no rekening
	if($crek > 0){
		$Faction = "../lib/update.php";
		$Vbutton = "Update";
		$sql = mssql_query("SELECT * FROM MedicalNoRekening A, Karyawan B WHERE A.NIK='$nik' AND A.NIK=B.NIK",$conn);
		$row = mssql_fetch_array($sql);
	}
	else{
		$Faction = "../lib/save.php";
		$Vbutton = "Simpan";
		$sql = mssql_query("SELECT * FROM Karyawan WHERE NIK='$nik'",$conn);
		$row = mssql_fetch_array($sql);
	}
?>
<table width="100%">
 <tr>
  <td class="line_bottom"><b>SETTING NO REKENING</b></td>
 </tr>
 <tr>
  <td>
	<form name="rekening" action="<?=$Faction?>" method="post">
  <table>
   <tr> 
    <td width="100">NIK</td>
	<td><input type="text" name="nik" value="<?=$row[NIK]?>" readonly="" />
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
	</td>
   </tr>
   <tr> 
    <td width="100">Nama</td>
	<td><input type="text" value="<?=$row[Nama]?>" name="nama" size="50" readonly="" /></td>
   </tr>   
  </table>
  </td>
 </tr>
 <tr>
  <td><hr noshade="noshade" size="-1" color="#EFEFEF" /></td>
 </tr>
 <tr>
  <td>
   <table width="100%">
    <tr>
	 <td width="150">No. Rekening:</td>
	 <td><input type="text" name="no_rek" value="<?=$row[no_rek]?>" maxlength="35" size="35" /></td>
	</tr>
    <tr>
	 <td width="150">Atas Nama Rekening:</td>
	 <td><input type="text" name="nama_rek" value="<?=$row[nama_rek]?>" maxlength="35" size="35" /></td>
	</tr>
	<tr>
	 <td>Nama Bank:</td>
	 <td>
	 <select name="nama_bank">
	  <?
	  	$gBank	= mssql_query("SELECT * FROM MstBank WHERE IdBank = '$row[IdBank]'",$conn);
		$rBank	= mssql_fetch_array($gBank);
		echo"<option value='$rBank[idBank]'>$rBank[NamaBank]</option>";
	  ?>
	  <option value="">--pilih--</option>
	  <?
	  	$sBank = mssql_query("SELECT * FROM MstBank ORDER BY IdBank",$conn);
		while($rBank = mssql_fetch_array($sBank)){
			echo"<option value='$rBank[IdBank]'>$rBank[NamaBank]</option>";
		}
	  ?>
	 </select>
	 </td>
	</tr>
	 <tr>
	  <td colspan="2"><hr noshade="noshade" size="-1" color="#EFEFEF" /></td>
	 </tr>
	<tr>
	 <td colspan="2" align="right">
	  <input type="hidden" name="cat" value="rekening" />
	  <input type="button" value="Batal" onclick="Javascript:history.back();" class="button" />
	  <input type="button" value="<?=$Vbutton?>" onclick="Javascript:ValidateR()" class="button" />
	  </td>
	</tr>
   </table>
   </form>
  </td>
 </tr>
</table>
<?
	}
?>
<script type="text/javascript">
//var f = document.forms[0];
//var g = document.forms['plafon_awal'];
//MaskInput(f.no_rek,"99999999999999999999999999999");
//MaskInput(f.plafon_kaca_mata,"9999999999999");
//MaskInput(f.plafon_rawat_jalan,"9999999999999");
//MaskInput(g.plafon_kaca_mata,"9999999999999");
//MaskInput(g.plafon_rawat_jalan,"9999999999999");
//]]>
</script>
<script type="text/javascript">
// script untuk popup calendar
<?
	if($show == "rekening"){
	
	}
	else{
?>
	var calA = new calendar1(document.forms[0].elements['date_setup']);
	calA.year_scroll = true;
	calA.time_comp = false;	
<?
	}
?>	
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>